package com.kjtpay.design_pattern.abstract_factory;

import androidx.annotation.Nullable;

/**
 * 工厂方法集中的类；可以是简单工厂；也可以用反射，通过字符串创建所需要的类
 */
class DataAccess {
    // "SqlServer"; 和 "Access"
    public static String db = "SqlServer";

    // 简单工厂的方法：离不开switch或者if
    public static IUser createUser() {
        IUser result = null;
        switch (db) {
            case "SqlServer":
                result = new SqlServerUser();
                break;
            case "Access":
                result = new AccessUser();
                break;
        }
        return result;
    }

    public static IDepartment createDepartment() {
        IDepartment result = null;
        switch (db) {
            case "SqlServer":
                result = new SqlServerDepartment();
                break;
            case "Access":
                result = new AccessDepartment();
                break;
        }
        return result;
    }

    // 反射的方法，暂时不写
}
